package com.mass.core.sys.dict.controller;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mass.core.sys.dict.model.SysDictType;
import com.mass.core.sys.dict.service.SysDictTypeService;
import com.mass.core.utils.AjaxResponse;

import java.util.List;


/**
 * annotation:SysDictType 控制层
 * created by pannan on 2017/08/25
 * 
 */
@RestController
@RequestMapping(value="/sys/dictType")
public class SysDictTypeController {

    private final static Logger LOGGER = LoggerFactory.getLogger(SysDictTypeController.class);



    @Autowired
    private SysDictTypeService sysDictTypeService;

    /**
     * 获取详情
     * @param id  对象id
     * @return
     */
    @RequestMapping(value="/getEntityById", method = RequestMethod.GET)
    public AjaxResponse getEntityById(@RequestParam("id") Long id){
        try {
            SysDictType sysDictType = this.sysDictTypeService.getEntityById(id);
            return AjaxResponse.success("ok", sysDictType);
        }catch (Exception e){
            LOGGER.error("select SysDictType error!",e);
            return AjaxResponse.error("error");
        }
    }
    /**
     * 添加数据词典类型
     *
     * @param sysDictType
     */
    @RequestMapping(value="/addEntity", method = RequestMethod.POST)
    public AjaxResponse addEntity(SysDictType sysDictType){
        try {
            sysDictType = this.sysDictTypeService.addEntity(sysDictType);
            return null == sysDictType ? AjaxResponse.error("error", sysDictType) : AjaxResponse.success("ok", sysDictType);
        }catch (Exception e){
            LOGGER.error("add SysDictType error!",e);
            return AjaxResponse.error("error",sysDictType);
        }
    }
    /**
     * 修改数据词典类型
     * @param sysDictType
     */
    @RequestMapping(value="/editEntity", method = RequestMethod.POST)
    public AjaxResponse editEntity(SysDictType sysDictType){
        try {
            return this.sysDictTypeService.editEntity(sysDictType) ? AjaxResponse.success("ok", sysDictType) : AjaxResponse.error("error", sysDictType);
        }catch (Exception e){
            LOGGER.error("edit SysDictType error!",e);
            return AjaxResponse.error("error",sysDictType);
        }
    }
    /**
     * 删除数据词典类型
     * @param id
     */
    @RequestMapping(value="/deleteEntity", method = RequestMethod.GET)
    public AjaxResponse deleteEntity(@RequestParam("id") Long id){
        try {
            return this.sysDictTypeService.deleteEntity(id) ? AjaxResponse.success("ok", id) : AjaxResponse.error("error",id);
        }catch (Exception e){
            LOGGER.error("delete SysDictType error!",e);
            return AjaxResponse.error("error");
        }
    }
    /**
     *验证编码唯一
     * @param typeCode  编码
     * */
    @RequestMapping(value="/checkTypeCodeIsExist", method = RequestMethod.POST)
    public boolean checkTypeCodeIsExist(@RequestParam("typeCode") String typeCode){

        return this.sysDictTypeService.checkTypeCodeIsExist(typeCode);

    }


    
    /**
     *查询全部词典类型
     *分页查询
     **/
    @RequestMapping(value="listAll", method = RequestMethod.GET)
    public AjaxResponse selectAllBy(){
        try {
        	 List<SysDictType> sysDictTypeList = this.sysDictTypeService.selectAll();
           return AjaxResponse.success("ok", sysDictTypeList);
        }catch (Exception e){
            LOGGER.error("SysDictType selectAllSysDictType error!",e);
            return null;
        }
    }
    
    
}
